package com.sq.ai.controller;

import com.sq.ai.base.BaseController;
import com.sq.ai.pojo.SysAlgor;
import com.sq.ai.service.SysAlgorService;
import com.sq.ai.vo.SysAlgorVo;
import com.sq.common.web.base.TableDataInfo;
import com.sq.common.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Li sir
 * @Date 2024/10/21
 */

@RestController
@RequestMapping("/api/algor/")
public class AlgorController extends BaseController {

    @Autowired
    private SysAlgorService sysAlgorService;


    @PostMapping("select")
    public TableDataInfo selectByWhere(@RequestBody SysAlgor sysAlgor){
        startPage(sysAlgor.getPageNum(),sysAlgor.getPageSize());
        List<SysAlgor> list = sysAlgorService.selectByWhere(sysAlgor);
        return getDataTable(list);
    }
    @PostMapping("selectAllAlgor")
    public List<SysAlgor> selectAllAlgor(@RequestBody SysAlgor sysAlgor){

        List<SysAlgor> list = sysAlgorService.selectByWhere(sysAlgor);
        return list;
    }
    @PostMapping("delete")
    public AjaxResult deleteAlgor(@RequestBody SysAlgor sysAlgor){

        boolean b = sysAlgorService.removeSysAlgor(sysAlgor.getAlgorId());
        if (b){
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }

    @GetMapping("del/{algorId}")
    public AjaxResult deleteAlgor(@PathVariable("algorId") String algorId){

        boolean b = sysAlgorService.removeSysAlgor(algorId);
        if (b){
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }

    @PostMapping("insertOrUpdate")
    public AjaxResult insertOrUpdate(@RequestBody SysAlgor sysAlgor){

        boolean b = sysAlgorService.insertOrUpdate(sysAlgor);
        if (b){
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }

    @GetMapping("getone/{algorId}")
    public AjaxResult getOneAlgor(@PathVariable("algorId") String algorId){
        SysAlgor sysAlgor = sysAlgorService.getOneAlgor(algorId);
        return AjaxResult.success(sysAlgor);
    }

    @GetMapping("algorLable")
    public AjaxResult getAlgorLabel(){
        List<SysAlgorVo> algorVoList = sysAlgorService.getAlgorLabel();
        return AjaxResult.success(algorVoList);
    }

}
